<template>
  <div class="box">
    <div class="box-content">
      <div class="newsList-box">
        <ColumnNewsItem v-for="(item, index) of list" :key="index" :data="item" class="newsItem" />
      </div>
      <div class="btn-group" v-if="paginationData.total > list.length">
        <el-button type="default" @click="loadMore">加载更多内容...</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { columnList } from '@/api/api'
import ColumnNewsItem from '@/components/ColumnNewsItem/index'
export default {
  components: {
    ColumnNewsItem
  },
  data() {
    return {
      bannerUrl: 'http://iot.vnest.net/api/files/down/1340189541046292480.jpeg',
      list: [],
      paginationData: {
        start: 0,
        limit: 12,
        total: 0
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    loadMore() {
      if (this.paginationData.total > this.list.length) {
        this.paginationData.start+=12
        this.getList()
      }
    },
    async getList() {
      const { start, limit } = this.paginationData
      const res = await columnList({start, limit})
      if (res.result === 0) {
        this.paginationData.total = res.count
        this.list = this.list.concat(res.list)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.box {
  background: #F1F1F1;
  .box-content {
    width: 1180px;
    margin: 0 auto;
    .newsList-box {
      overflow: hidden;
      padding-top: 100px;
      padding-bottom: 70px;
      .newsItem {
        float: left;
        margin-bottom: 20px;
        margin-right: 20px;
        &:nth-child(3n+3) {
          margin-right: 0;
        }
      }
    }
    .btn-group {
      text-align: center;
      padding-bottom: 100px;
    }
  }
}
</style>